package com.banmoon.algorithm.leetcode;

/**
 * <a href="https://leetcode.cn/problems/plus-one/">链接</a>
 *
 * @author banmoon
 */
public class Question66 {

    public static void main(String[] args) {

    }

    public int[] plusOne(int[] digits) {
        boolean flag = false;
        int i = digits.length - 1;
        do {
            int temp = digits[i] + 1;
            flag = temp == 10;
            digits[i] = temp % 10;
            i--;
        } while (flag && i >= 0);
        if (flag) {
            int[] result = new int[digits.length + 1];
            result[0] = 1;
            for (int j = 1; j < result.length; j++) {
                result[j] = digits[j - 1];
            }
            return result;
        }
        return digits;
    }

}
